/*
 * Copyright (C) 2009 CodeWerkz
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.codewerkz.prompty;

import android.app.Activity;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.codewerkz.util.SettingsLoader.LoadSettings;

/**
 * Class for Help activity of Program..
 * 
 * @author ChaZ
 */
public class Help extends Activity implements OnClickListener, LoadSettings {
	
	// Set up globals.
	private Button mBtnPresentation;
	private Button mBtnSlides;
	private Button mBtnSlideShow;
	private TextView mTvDesc;
	
	/**
	 * Runs this function when the Activity is started.
	 * 
	 * @return void
	 */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	
    	// Set up the layout.
    	this.setContentView(R.layout.help);
    	
    	// Depending on the call, load a different layout.
        Bundle extras = this.getIntent().getExtras();
        Integer helpPage = extras != null ? extras.getInt("helpPage") : null;
    	
        // Set up views.
    	this.mTvDesc = (TextView) this.findViewById(R.id.help_text);
    	this.mBtnPresentation = (Button) this.findViewById(R.id.help_helpPresentationButton);
    	this.mBtnSlides = (Button) this.findViewById(R.id.help_helpSlidesButton);
    	this.mBtnSlideShow = (Button) this.findViewById(R.id.help_helpSlideShowButton);
    	
        // Set up the page.
        this.setUpHelp(helpPage);
        
    	// Set up onClick listeners.
    	this.mBtnPresentation.setOnClickListener(this);
    	this.mBtnSlides.setOnClickListener(this);
    	this.mBtnSlideShow.setOnClickListener(this);
    	
    	loadSettings();
    }
    
	/**
	 * Loads the settings from the Main Activity and set's up any views with changes such as font. 
	 * 
	 * @param void
	 * @return void
	 */
	@Override
	public void loadSettings() {
		this.mBtnPresentation.setTextSize(TypedValue.COMPLEX_UNIT_PX, PresentationList.sFontSizePx);
		this.mBtnSlides.setTextSize(TypedValue.COMPLEX_UNIT_PX, PresentationList.sFontSizePx);
		this.mBtnSlideShow.setTextSize(TypedValue.COMPLEX_UNIT_PX, PresentationList.sFontSizePx);
		this.mTvDesc.setTextSize(TypedValue.COMPLEX_UNIT_PX, PresentationList.sFontSizePx);
	}
    
	/**
	 * Runs when an onClick listener is triggered for the Buttons.
	 * 
	 * @param v View ID of the button pressed.
	 * @return void
	 */
	@Override
	public void onClick(View v) {
		if(v == this.mBtnPresentation) {         
            // Load Presentation Help
			this.setUpHelp(1);
		} 
		else if (v == this.mBtnSlides) {
            // Load Slides Help
			this.setUpHelp(2);
		}
		else if (v == this.mBtnSlideShow) {
			// Load Slide Show help
			this.setUpHelp(3);
		}
	}
	
	/**
	 * Runs when the Activity is about to be destroyed for Garbage Collection.
	 * 
	 * @return void
	 */
	@Override
	public void onDestroy() {
		super.onDestroy();
		
		// Set all the references to buttons etc. to null.
		mBtnPresentation = null;
		mBtnSlides = null;
		mBtnSlideShow = null;
		mTvDesc = null;
	}
    
	/**
	 * Helper function to set up the Help screen (Load the content and titles)
	 * 
	 * @param i Integer for the help screen to load.
	 * @return void 
	 */
    protected void setUpHelp(Integer i) {
    	
    	this.mBtnPresentation.setEnabled(true);
    	this.mBtnSlides.setEnabled(true);
    	this.mBtnSlideShow.setEnabled(true);
    	
    	// Switches an integer, depending on which help screen it is.
        switch(i) {
        // For each case, load the relevant content view and set it's title.
	        case 1:
	        	this.setTitle(R.string.title_help_presentation);
	        	this.mTvDesc.setText(R.string.help_presentation_help);
	        	this.mBtnPresentation.setEnabled(false);
	        	break;
	        case 2:
	        	this.setTitle(R.string.title_help_slides);
	        	this.mTvDesc.setText(R.string.help_slides_help);
	        	this.mBtnSlides.setEnabled(false);	        	
	        	break;
	        case 3:
	        	this.setTitle(R.string.title_help_slideshow);
	        	this.mTvDesc.setText(R.string.help_slideshow_help);
	        	this.mBtnSlideShow.setEnabled(false);
	        	break;
        }
    }
}